$(".Us_bt").click(function() {
    $("#Us_agmt_bg").css("display", "none")
})
$(".Reg_but").click(function() {
    $("#Us_agmt_bg").css("display", "flex")
})

var nm_dis = 0
var stid_dis = 0
var pwd_dis = 0
$("#Reg_bt_name,#Reg_bt_studentId,#Reg_pwd_one,#Reg_pwd_tow").keydown(function() {
    if ($("#Reg_bt_name").val() == "") {
        $("#Reg_bt_name").css("border-bottom", "solid 2px red ")
        nm_dis = 0
    } else {
        $("#Reg_bt_name").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        nm_dis = 1
    }
    if ($("#Reg_bt_studentId").val() == "") {
        $("#Reg_bt_studentId").css("border-bottom", "solid 2px red ")
        stid_dis = 0
    } else {
        $("#Reg_bt_name").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        stid_dis = 1
    }
    if ($("#Reg_pwd_one").val() == "" && $("#Reg_pwd_tow").val() == "") {
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px red ")
        pwd_dis = 0
    } else if ($("#Reg_pwd_one").val() == "") {
        $("#Reg_pwd_one").css("border-bottom", "solid 2px red ")
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px red ")
        pwd_dis = 0
    } else if ($("#Reg_pwd_one").val() == "") {
        $("#Reg_pwd_one").css("border-bottom", "solid 2px red ")
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px red ")
        pwd_dis = 0
    } else if ($("#Reg_pwd_one").val() != $("#Reg_pwd_tow").val()) {
        $("#Reg_pwd_one").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px red ")
        pwd_dis = 0
    } else {
        $("#Reg_pwd_one").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        pwd_dis = 1
    }
    
    if(nm_dis == 0){
    	$("#Register_side_errMsg").text("昵称未填写")
    }
    else if(stid_dis == 0){
    	$("#Register_side_errMsg").text("学号未填写")
    }
    else if(pwd_dis == 0){
    	$("#Register_side_errMsg").text("密码未填写或两次填写的密码不同")
    }
})
$("#Reg_bt_name,#Reg_bt_studentId,#Reg_pwd_one,#Reg_pwd_tow").keyup(function() {
    if ($("#Reg_bt_name").val() != "") {
        $("#Reg_bt_name").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        nm_dis = 1
    } else {
        $("#Reg_bt_name").css("border-bottom", "solid 2px red ")
        nm_dis = 0
    }
    if ($("#Reg_bt_studentId").val() != "") {
        $("#Reg_bt_studentId").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        stid_dis = 1
    } else {
        $("#Reg_bt_studentId").css("border-bottom", "solid 2px red ")
        stid_dis = 0
    }
    if ($("#Reg_pwd_one").val() == "" && $("#Reg_pwd_tow").val() == "") {
        $("#Reg_pwd_one").css("border-bottom", "solid 2px red ")
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px red ")
        pwd_dis = 0
    } else if ($("#Reg_pwd_one").val() == "") {
        $("#Reg_pwd_one").css("border-bottom", "solid 2px red ")
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px red ")
        pwd_dis = 0
    } else if ($("#Reg_pwd_one").val() == "") {
        $("#Reg_pwd_one").css("border-bottom", "solid 2px red ")
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px red ")
        pwd_dis = 0
    } else if ($("#Reg_pwd_one").val() != $("#Reg_pwd_tow").val()) {
        $("#Reg_pwd_one").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px red ")
        pwd_dis = 0
    } else {
        $("#Reg_pwd_one").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        $("#Reg_pwd_tow").css("border-bottom", "solid 2px rgb(0,0,0,0.3)")
        pwd_dis = 1
    }
    if ($("#Rr_ch").prop("checked") && nm_dis == 1 && stid_dis == 1 && pwd_dis == 1) {
        $('#Rr_bt').attr("disabled", false);
    } else {
        $('#Rr_bt').attr("disabled", true);
    }
    if(nm_dis == 0){
    	$("#Register_side_errMsg").text("昵称未填写")
    }
    else if(stid_dis == 0){
    	$("#Register_side_errMsg").text("学号未填写")
    }
    else if(pwd_dis == 0){
    	$("#Register_side_errMsg").text("密码未填写或两次填写的密码不同")
    }
    else{
    	$("#Register_side_errMsg").text("")
    }
})
$("#Rr_ch").click(function() {
    if ($("#Rr_ch").prop("checked") && nm_dis == 1 && stid_dis == 1 && pwd_dis == 1) {
        $('#Rr_bt').attr("disabled", false);
    } else {
        $('#Rr_bt').attr("disabled", true);
    }
});

$("#Reg_bt_name").focus(function() {
    $("#Reg_h4_name").text("")
})
$("#Reg_bt_name").blur(function() {
    if ($("#Reg_bt_name").val() == "") {
        $("#Reg_h4_name").text("昵称")
    } else {
        $("#Reg_h4_name").text("")
    }
})
$("#Reg_bt_studentId").focus(function() {

    $("#Reg_h4_id").text("")

})
$("#Reg_bt_studentId").blur(function() {
    if ($("#Reg_bt_studentId").val() == "") {
        $("#Reg_h4_id").text("学号")
    } else {
        $("#Reg_h4_id").text("")
    }
})
$("#Reg_pwd_one").focus(function() {
    $("#Reg_h4_pwd_one").text("")
})
$("#Reg_pwd_one").blur(function() {
    if ($("#Reg_pwd_one").val() == "") {
        $("#Reg_h4_pwd_one").text("密码")
    } else {
        $("#Reg_h4_pwd_one").text("")
    }
})
$("#Reg_pwd_tow").focus(function() {

    $("#Reg_h4_pwd_tow").text("")

})
$("#Reg_pwd_tow").blur(function() {
        if ($("#Reg_pwd_tow").val() == "") {
            $("#Reg_h4_pwd_tow").text("密码")
        } else {
            $("#Reg_h4_pwd_tow").text("")
        }
    })
    //注册

$("#Rr_bt").click(function() {
    $.post(
        "http://123.57.207.22:8080/api/register", {
            name: $("#Reg_bt_name").val(),
            studyNo: $("#Reg_bt_studentId").val(),
            college: $("#Reg_sel option:selected").val(),
            password: $("#Reg_pwd_one").val(),
        },
        function(res) {
            console.log(res)
            if (res.msg=="注册成功") {
                $.cookie('admin', res.admin,{path:'/'}); //权限
                $.cookie('uId', res.uId,{path:'/'}); //id
                alert("注册成功")
                window.location.href = "../index.html"
            }else if(res.msg=="您已注册过了"){
            	  alert("您已注册过")
            }
            else {
                alert("网路似乎出现问题")
            }
        })
})